/****************商品返点********************************/
//1.选择单据
function chooseDJF(obj){
	var hId = $('#pdm_addWinTable input[qucln=H_ID]').val();
	if(hId == '' || hId == null){
		$.messager.alert("温馨提示",'亲，请先选择商品！');
		return;
	}
	_data_qw('fdx','ds_fx_xs_fd','pdm_sure1','44','spfdFunc',''); 
}
//2.添加明细回调的函数（重写查询方法）
function spfdFunc(prefix){
	_zae_t_dg(prefix);
	//重写查询按钮的方法
	$('#'+prefix+'_commDataLeftD a[id='+prefix+'_dataQuery]').attr('onclick','spfdItemQuery(this)');
}
//3.查询按钮调用的方法
function spfdItemQuery(obj){
	var prefix=$(obj).attr('pre');
	var dsId=$(obj).attr('dsid');
	var resultDG = 'DATA_DATALIST';
	var comUseConf='commUseD';
	var otherConfig = "";
	//获取商品Id
	var hId = $('#pdm_addWinTable input[qucln=H_ID]').val();
	var oid = $('#pdm_addWinTable input[qucln=O_ID_LASTGR]').val();
	if(hId == '' || hId == null){
		hId = 'null';
	}
	if(oid == '' || oid == null){
		oid = 'null';
	}
	otherConfig = "1-H_ID-"+hId+"-inc|+1-O_ID_LASTGR-"+oid+"-inc|+"; 
	var comUse = parseConfig(prefix+"_"+comUseConf);
	var useConf = otherConfig+comUse;
	var getAllRows = $('#pdm_addItemDatagrid').datagrid('getRows');
	$('#'+prefix+"_"+resultDG).datagrid({
		url:_m_url+'framework/loadDataQ',
		queryParams:{'dsId':dsId,'config':useConf},
		onLoadSuccess:function(){
			var dataRows = $('#'+prefix+"_"+resultDG).datagrid('getRows');
			if(dataRows.length>0){
				for(var i = 0;i<dataRows.length;i++){
					if(getAllRows.length>0){
						for(var j = 0;j<getAllRows.length;j++){
							if(dataRows[i].PX_ID == getAllRows[j].XS_ID){
								$('#'+prefix+"_"+resultDG).datagrid('deleteRow',i);
							}
						}
					}
				}
			}
		}
	});
}
//4.弹窗的确定按钮
function _pdm_sure1(){
	$('#fdx_DATA_PARENT_PANEL').window('close');
	var selRows = $('#fdx_DATA_DATALIST').datagrid('getSelections');

	for ( var i = 0; i < selRows.length; i++) {
		$('#pdm_addItemDatagrid').datagrid('appendRow', {
			CLIENT_ID:selRows[i].CLIENT_ID,
			H_AMOUNT:selRows[i].H_AMOUNT,
			H_DISCOUNT:selRows[i].H_DISCOUNT,
			H_PRICE_REAL:selRows[i].H_PRICE_REAL,
			REAL_MONEY:selRows[i].REAL_MONEY_ITEM,
			XS_CODE:selRows[i].PX_CODE,
			XS_ID:selRows[i].PX_ID,
			XS_INPUTDATE:selRows[i].INPUT_DATE,
			XS_ITEM_ID:selRows[i].PX_ITEM_ID,
			H_PRICE:selRows[i].H_PRICE
		});
	}
//	 fx_allItemJs();
}
//整个明细界面的计算
//function fx_allItemJs(){
//	var allRows = $('#pdm_addItemDatagrid').datagrid('getRows');
//	for(var i =0;i<allRows.length;i++){
//		var srDiscount = allRows[i]["H_DISCOUNT_MOD"];				   //调整后折扣
//		var hprice =allRows[i]["H_PRICE"]; 							   //定价
//		var yxj = allRows[i]["H_PRICE_REAL"]; 						   //原销价
//		var zsy = allRows[i]["REAL_MONEY"]; 						   //总实洋
//		var amount = allRows[i]["H_AMOUNT"];	
//		if(srDiscount == '' || srDiscount == null){
//			srDiscount = 1;
//		}
//		if(hprice == '' || hprice == null){
//			hprice = 0;
//		}
//		if(yxj == '' || yxj== null){
//			yxj = 0;
//		}
//		if(zsy == '' || zsy == null){
//			zsy = 0;
//		}
//		if(amount == '' || amount == null){
//			amount = 0;
//		}
//		allRows[i]["H_PRICE_REAL_MOD"] = (hprice * srDiscount).toFixed(2); 			   //调整后销价
//		allRows[i]["H_PRICE_RL"] = (yxj - hprice * srDiscount).toFixed(2); 			   //让利单价
//		allRows[i]["REAL_MONEY_MOD"] = (amount * hprice * srDiscount).toFixed(2);	   //调整后实洋
//		$('#pdm_addItemDatagrid').datagrid('beginEdit',i);
//		$('#pdm_addItemDatagrid').datagrid('endEdit',i);
//	}
//}
//明细界面上的计算方法(折扣变化的时候，界面上的计算)
function fx_jsItem(ispl){
	var curDiv=$("div[realdsid][prefix][dsid]"); 				 //获取datagrid的div
	var i=$(curDiv).attr("currentIndex");
	var allRows = $(curDiv).datagrid('getRows');
	if(ispl=="false"){
		$(curDiv).datagrid('endEdit',i);
	}
	var srDiscount = allRows[i]["H_DISCOUNT_MOD"];				   //调整后折扣
	var hprice =allRows[i]["H_PRICE"]; 							   //定价
	var yxj = allRows[i]["H_PRICE_REAL"]; 						   //原销价
	var zsy = allRows[i]["REAL_MONEY"]; 						   //总实洋
	var amount = allRows[i]["H_AMOUNT"];						   //数量
	if(srDiscount == '' || srDiscount == null){
		srDiscount = 1;
	}
	if(hprice == '' || hprice == null){
		hprice = 0;
	}
	if(yxj == '' || yxj== null){
		yxj = 0;
	}
	if(zsy == '' || zsy == null){
		zsy = 0;
	}
	if(amount == '' || amount == null){
		amount = 0;
	}
	allRows[i]["H_PRICE_REAL_MOD"] = (hprice * srDiscount).toFixed(2); 			   //调整后销价
	//allRows[i]["H_PRICE_RL"] = (yxj - hprice * srDiscount).toFixed(2); 		
	//allRows[i]["REAL_MONEY_MOD"] = (amount * hprice * srDiscount).toFixed(2);	
	var rlPrice = (hprice * srDiscount).toFixed(2); 
	allRows[i]["H_PRICE_RL"] = (hprice * srDiscount).toFixed(2); 			   //让利单价
	allRows[i]["REAL_MONEY_MOD"] = (amount * rlPrice).toFixed(2);	   //调整后实洋
	if(ispl=="false"){
		$(curDiv).datagrid('refreshRow',i);
		$(curDiv).datagrid('beginEdit',i);
	}
}

